# scrapy genspider qustory qu.la 创建爬虫文件的命令,也可以手动创建爬虫文件
import scrapy
from bs4 import BeautifulSoup

class QustorySpider(scrapy.Spider):
    name = "qustory"
    allowed_domains = ["m.xbiqugew.com"]
    start_urls = ["https://m.xbiqugew.com/book/21506/14009282.html"]

    def parse(self, response):
        soup = BeautifulSoup(response.text, "html.parser")
        title = soup.select_one('h1#nr_title').text
        content = soup.select_one('div#nr1').text
        next = soup.select_one('a#pb_next').get('href')
        completed_next = 'https://m.xbiqugew.com/book/21506/' + next
        yield {'title': title, 'content': content, 'next': next, 'completed_next': completed_next}

        yield scrapy.Request(completed_next, callback=self.parse)

